using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using ADESSA.Business;
using ADESSA.Entities;
using FetCo.Framework;
using FetCo.Web;
using System.IO;

public partial class MProductsell : System.Web.UI.Page
{
    protected long Id
    {
        get
        {
            if (HttpContext.Current.Request.QueryString["Id"] == null)
                return long.MinValue;
            else
                return long.Parse(HttpContext.Current.Request.QueryString["Id"]);
        }
    }
    protected long con1
    {
        get
        {
            if (HttpContext.Current.Request.QueryString["con1"] == null)
                return long.MinValue;
            else
                return long.Parse(HttpContext.Current.Request.QueryString["con1"]);
        }
    }
    protected long con2
    {
        get
        {
            if (HttpContext.Current.Request.QueryString["con1"] == null)
                return long.MinValue;
            else
                return long.Parse(HttpContext.Current.Request.QueryString["con2"]);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {

        if (IsPostBack)
            return;

        if (this.con1 == 1)
        {
            divcontent1.Visible = false;
            divcontent2.Visible = true;
            divcontent3.Visible = false;
        }
        else if (con2 == 2)
        {
            divcontent1.Visible = false;
            divcontent2.Visible = false;
            divcontent3.Visible = true;
        }
        else
        {
            divcontent1.Visible = true;
            divcontent2.Visible = false;
            divcontent3.Visible = false;
        }
        LoadAddmore();
        LoadCurrunce();
        LoadUnitType();
        LoadUnitTypePrice();
        LoadCategoryPro();
        loadSubcat();
        LoadData();
        LoadCurent();

    }
    #region Load Binding Product sell
    private void LoadData()
    {
        ADESSA.Entities.ProductSell _ProductSell = new ADESSA.Entities.ProductSell();
        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            _ProductSell = ProductSellService.GetProductSell(this.Id);
            if (_ProductSell != null)
            {
                txtName.Value = _ProductSell.Title;
                txtListingDescription.Value = _ProductSell.ProductDescription;
                if (!string.IsNullOrEmpty(_ProductSell.Image))
                {
                    img.Src = "photos/" + _ProductSell.Image;
                }
                else
                {
                    img.Visible = false;
                }
                #region Load Add more
                LoadAddmore();
                #endregion
                ProductCat _ProductCatSubSub = ProductCatService.GetProductCat(_ProductSell.CatId);
                if (_ProductCatSubSub != null)
                {
                    ProductCat _ProductCatSub = ProductCatService.GetProductCat(_ProductCatSubSub.Parrentid);
                    if (_ProductCatSub != null)
                    {
                        ddlProCat.SelectedValue = _ProductCatSub.Parrentid.ToString();
                        loadSubcat();
                        ddlSubCat.SelectedValue = _ProductCatSub.ProCateID.ToString();
                        loadSubSubcat();
                        ddlSubSubCat.SelectedValue = _ProductSell.CatId.ToString();
                    }
                }
                txtproductkey.Value = _ProductSell.KeyWord;
                txtMinOderQuantity.Value = _ProductSell.MinOrderQuantity;
                ddlUnittype1.SelectedValue = _ProductSell.MinQuantityTypeId.ToString();
                txtMinOtherQuantity.Value = _ProductSell.MinQuantityOther;
                ddlCurency.SelectedValue = _ProductSell.FOBPriceId.ToString();
                txtFOBPrice1.Value = _ProductSell.PriceSmall;
                txtFOBPrice2.Value = _ProductSell.PriceLarge;
                ddlUnittype2.SelectedValue = _ProductSell.PerTypeId.ToString();
                txtPort.Value = _ProductSell.Port;
                txtPaymentTerms.Value = _ProductSell.PaymentTerms;
                txtProductionCapacity.Value = _ProductSell.Production;
                txtDeliveryTime.Value = _ProductSell.DeliveryTime;
                txtPackagingDetails.Value = _ProductSell.PackagingDetail;
                //txtOrder.Value = _ProductSell.Order.ToString();
                //ddlMember.SelectedValue = _ProductSell.MemberId.ToString();
                txtDetailDescription.Value = _ProductSell.Description;
            }
        }

    }
    protected void rptAdd_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        AddMoreSellProduct _AddMoreSellProduct = (AddMoreSellProduct)e.Item.DataItem;
        HiddenField hdf = (HiddenField)e.Item.FindControl("hdf");
        TextBox txtTitlerpt = (TextBox)e.Item.FindControl("txtTitlerpt");
        TextBox txtNamerpt = (TextBox)e.Item.FindControl("txtNamerpt");
        txtTitlerpt.Text = _AddMoreSellProduct.Title;
        txtNamerpt.Text = _AddMoreSellProduct.Name;
        hdf.Value = _AddMoreSellProduct.AddMoreId.ToString();
    }
    #endregion
    #region Load dropdownlist here
    private void LoadCurrunce()
    {
        ddlCurency.Items.Clear();
        ddlCurency.Items.Add(new ListItem("- - Curency - -", "0"));
        ADESSA.Entities.UnitPriceCollection _UnitPriceCollection = UnitPriceService.GetUnitPriceList(UnitPriceColumns.Order, OrderDirection.ASC);
        if (_UnitPriceCollection.Count > 0)
        {
            foreach (ADESSA.Entities.UnitPrice _UnitPrice in _UnitPriceCollection)
            {
                ddlCurency.Items.Add(new ListItem(_UnitPrice.Title, _UnitPrice.UnitPriceId.ToString()));
            }
        }
    }
    private void LoadUnitType()
    {
        ddlUnittype1.Items.Clear();
        ddlUnittype1.Items.Add(new ListItem("- - Unit type - -", "0"));
        ADESSA.Entities.UnitTypeCollection _UnitTypeCollection = UnitTypeService.GetUnitTypeList(UnitTypeColumns.Order, OrderDirection.ASC);
        if (_UnitTypeCollection.Count > 0)
        {
            foreach (ADESSA.Entities.UnitType _UnitType in _UnitTypeCollection)
            {
                ddlUnittype1.Items.Add(new ListItem(_UnitType.Name, _UnitType.UnitTypeId.ToString()));
            }
        }
    }
    private void LoadUnitTypePrice()
    {
        ddlUnittype2.Items.Clear();
        ddlUnittype2.Items.Add(new ListItem("- - Unit type - -", "0"));
        ADESSA.Entities.UnitTypeCollection _UnitTypeCollection = UnitTypeService.GetUnitTypeList(UnitTypeColumns.Order, OrderDirection.ASC);
        if (_UnitTypeCollection.Count > 0)
        {
            foreach (ADESSA.Entities.UnitType _UnitType in _UnitTypeCollection)
            {
                ddlUnittype2.Items.Add(new ListItem(_UnitType.Name, _UnitType.UnitTypeId.ToString()));
            }
        }
    }
    private void LoadCategoryPro()
    {

        ddlProCat.Items.Clear();
        ddlProCat.Items.Add(new ListItem("- - - -Select Category- - - -", "0"));
        ddlSubCat.Items.Clear();
        ddlSubCat.Items.Add(new ListItem("- - - -Select SubCategory- - - -", "0"));
        ddlSubSubCat.Items.Clear();
        ddlSubSubCat.Items.Add(new ListItem("- - - -Select SubSubCategory- - - -", "0"));
        Criteria cri = new Criteria();
        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.CatLevel + "]", 0, Condition.EQUAL, Condition.AND);
        ProductCatCollection _ProductSellCollection = ProductCatService.GetProductCatListByParam("[" + ProductCat._Table + "].[" + ProductCatColumns.SortOrder + "]", OrderDirection.ASC, cri.Criter);
        if (_ProductSellCollection.Count > 0)
        {
            foreach (ProductCat _ProductSell in _ProductSellCollection)
            {
                ddlProCat.Items.Add(new ListItem(_ProductSell.Name, _ProductSell.ProCateID.ToString()));
            }
        }
    }
    private void loadSubcat()
    {
        ddlSubCat.Items.Clear();
        ddlSubCat.Items.Add(new ListItem("- - - -Select SubCategory- - - -", "0"));
        Criteria cri = new Criteria();

        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.CatLevel + "]", 1, Condition.EQUAL, Condition.AND);
        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.Parrentid + "]", Utility.ParseToBigint(ddlProCat.SelectedValue), Condition.EQUAL, Condition.AND);
        ProductCatCollection _ProductSellCollection = ProductCatService.GetProductCatListByParam("[" + ProductCat._Table + "].[" + ProductCatColumns.SortOrder + "]", OrderDirection.ASC, cri.Criter);
        if (_ProductSellCollection.Count > 0)
        {
            foreach (ProductCat _ProductSell in _ProductSellCollection)
            {
                ddlSubCat.Items.Add(new ListItem(_ProductSell.Name, _ProductSell.ProCateID.ToString()));
            }
        }
    }
    private void loadSubSubcat()
    {
        ddlSubSubCat.Items.Clear();
        ddlSubSubCat.Items.Add(new ListItem("- - - -Select SubCategory- - - -", "0"));
        Criteria cri = new Criteria();

        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.CatLevel + "]", 2, Condition.EQUAL, Condition.AND);
        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.Parrentid + "]", Utility.ParseToBigint(ddlSubCat.SelectedValue), Condition.EQUAL, Condition.AND);
        ProductCatCollection _ProductSellCollection = ProductCatService.GetProductCatListByParam("[" + ProductCat._Table + "].[" + ProductCatColumns.SortOrder + "]", OrderDirection.ASC, cri.Criter);
        if (_ProductSellCollection.Count > 0)
        {
            foreach (ProductCat _ProductSell in _ProductSellCollection)
            {
                ddlSubSubCat.Items.Add(new ListItem(_ProductSell.Name, _ProductSell.ProCateID.ToString()));
            }
        }
    }
    protected void ddlProSubCat_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        ddlSubCat.Items.Clear();
        ddlSubCat.Items.Add(new ListItem("- - - -Select SubCategory- - - -", "0"));
        Criteria cri = new Criteria();
        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.CatLevel + "]", 1, Condition.EQUAL, Condition.AND);
        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.Parrentid + "]", Utility.ParseToBigint(ddlProCat.SelectedValue), Condition.EQUAL, Condition.AND);
        ProductCatCollection _ProductSellCollection = ProductCatService.GetProductCatListByParam("[" + ProductCat._Table + "].[" + ProductCatColumns.SortOrder + "]", OrderDirection.ASC, cri.Criter);
        if (_ProductSellCollection.Count > 0)
        {
            foreach (ProductCat _ProductSell in _ProductSellCollection)
            {
                ddlSubCat.Items.Add(new ListItem(_ProductSell.Name, _ProductSell.ProCateID.ToString()));
            }
        }
    }
    protected void ddlSubCat_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        ddlSubSubCat.Items.Clear();
        ddlSubSubCat.Items.Add(new ListItem("- - - -Select SubSubCategory- - - -", "0"));
        Criteria cri = new Criteria();
        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.CatLevel + "]", 2, Condition.EQUAL, Condition.AND);
        cri.add("[" + ProductCat._Table + "].[" + ProductCatColumns.Parrentid + "]", Utility.ParseToBigint(ddlSubCat.SelectedValue), Condition.EQUAL, Condition.AND);
        ProductCatCollection _ProductSellCollection = ProductCatService.GetProductCatListByParam("[" + ProductCat._Table + "].[" + ProductCatColumns.SortOrder + "]", OrderDirection.ASC, cri.Criter);
        if (_ProductSellCollection.Count > 0)
        {
            foreach (ProductCat _ProductSell in _ProductSellCollection)
            {
                ddlSubSubCat.Items.Add(new ListItem(_ProductSell.Name, _ProductSell.ProCateID.ToString()));
            }
        }
    }
    #endregion Load about dropdownlist
    #region LoadCurent
    #region LoadCurent
    private void LoadCurent()
    {
        ContentPlaceHolder c = Page.Master.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
        UserControl usc = c.FindControl("MainMenu1") as UserControl;
        HtmlAnchor hrfMproductsell = (HtmlAnchor)usc.FindControl("hrfMproductsell");
        hrfMproductsell.Attributes.Add("class", "selected1");
    }

    #endregion
    #endregion

    #region Load Add more
    private void LoadAddmore()
    {
        Criteria cri = new Criteria();
        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            cri.add(AddMoreSellProductColumns.ProductId, long.Parse(Request.QueryString["id"]), Condition.EQUAL, Condition.AND);
        else
            cri.add(AddMoreSellProductColumns.ProductId, 0, Condition.EQUAL, Condition.AND);
        AddMoreSellProductCollection _AddMoreSellProductCollection = AddMoreSellProductService.GetAddMoreSellProductListByParam(AddMoreSellProductColumns.AddMoreId, OrderDirection.ASC, cri.Criter);
        if (_AddMoreSellProductCollection.Count > 0)
        {
            rptAdd.DataSource = _AddMoreSellProductCollection;
            rptAdd.DataBind();
            lndelete.Visible = true;
        }
        else
        {
            lndelete.Visible = false;
        }
    }
    #endregion
    #region VoidSave and Reset
    
    protected void btnexit_Click(object sender, EventArgs e)
    {
        Response.Redirect("Sellingleads.aspx");
    }
    #endregion
    protected void lndelete_Click(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in this.rptAdd.Items)
        {
            HtmlInputCheckBox chkDelete = (HtmlInputCheckBox)item.FindControl("chkDelete");
            if (chkDelete.Checked == true)
            {
                HiddenField hdf = (HiddenField)item.FindControl("hdf");
                string strhidID = hdf.Value;
                long ID = long.Parse(strhidID);

                try
                {

                    AddMoreSellProductService.DeleteAddMoreSellProduct(ID);
                }
                catch
                {
                    //lb_error.Text = "Dont's delete this item because it is getting using another items";
                }
            }
        }
        if (this.Id != long.MinValue)
            Response.Redirect("MProductsell.aspx?id=" + this.Id + "");
        else
            Response.Redirect("MProductsell.aspx");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.Id != long.MinValue)
        {
            ProductSell _ProductSell = ProductSellService.GetProductSell(this.Id);
            string path = Server.MapPath(RTISettings.NewsPictureFolder);

            if (_ProductSell.Image != null && File.Exists(Path.Combine(path, _ProductSell.Image)))
            {
                File.Delete(Path.Combine(path, _ProductSell.Image));
            }
            if (_ProductSell.ThumbnailImage != null && File.Exists(Path.Combine(path, _ProductSell.ThumbnailImage)))
            {
                File.Delete(Path.Combine(path, _ProductSell.ThumbnailImage));
            }
            _ProductSell.Image = "";
            _ProductSell.ThumbnailImage = "";
            ProductSellService.UpdateProductSell(_ProductSell);

        }
    }
    private void getvalueadd()
    {
        string Title = txt.Value;
        string Name = txt1.Value;
        String[] Namearry;
        Namearry = Name.Split(',');
        String[] Titilearry;
        Titilearry = Title.Split(',');
        for (int i = 0; i < Titilearry.Length - 1 && i < Namearry.Length - 1; i++)
        {
            string a = Titilearry[i];
            string b = Namearry[i];
            if (!string.IsNullOrEmpty(a) && !string.IsNullOrEmpty(b))
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    AddMoreSellProduct _AddMoreSellProduct = new AddMoreSellProduct();
                    _AddMoreSellProduct.ProductId = long.Parse(Request.QueryString["id"]);
                    _AddMoreSellProduct.Title = a;
                    _AddMoreSellProduct.Name = b;
                    AddMoreSellProductService.CreateAddMoreSellProduct(_AddMoreSellProduct);
                }
                else
                {
                    AddMoreSellProduct _AddMoreSellProduct = new AddMoreSellProduct();
                    _AddMoreSellProduct.ProductId = 0;
                    _AddMoreSellProduct.Title = a;
                    _AddMoreSellProduct.Name = b;
                    AddMoreSellProductService.CreateAddMoreSellProduct(_AddMoreSellProduct);
                }
            }
        }
        txt.Value = "";
        txt1.Value = "";
    }

    protected void btncontinues1_OnClick(object sender, EventArgs e)
    {

        getvalueadd();
        #region update Add
        foreach (RepeaterItem item in rptAdd.Items)
        {
            TextBox txtNamerpt = (TextBox)item.FindControl("txtNamerpt");
            TextBox txtTitlerpt = (TextBox)item.FindControl("txtTitlerpt");
            HiddenField hidID = (HiddenField)item.FindControl("hdf");
            long ID = long.Parse(hidID.Value);
            AddMoreSellProduct _AddMoreSellProduct = AddMoreSellProductService.GetAddMoreSellProduct(ID);
            _AddMoreSellProduct.Title = txtTitlerpt.Text;
            _AddMoreSellProduct.Name = txtNamerpt.Text;
            if (this.Id != long.MinValue && this.Id != 0)
            {
                _AddMoreSellProduct.ProductId = this.Id;
            }
            else
            {
                _AddMoreSellProduct.ProductId = 0;
            }
            AddMoreSellProductService.UpdateAddMoreSellProduct(_AddMoreSellProduct);
        }
        #endregion
        ADESSA.Entities.ProductSell _ProductSell = new ADESSA.Entities.ProductSell();
        if (this.Id != long.MinValue && this.Id != 0)
        {
            _ProductSell = ProductSellService.GetProductSell(this.Id);
        }
        if (Session["MemberId"] != null)
        {
            _ProductSell.MemberId = long.Parse(Session["MemberId"].ToString());
        }
        else
        {
            Response.Redirect("MemberLogin.aspx");
        }
        _ProductSell.UpdatedDate = DateTime.Now;
        
        _ProductSell.Title = txtName.Value;
        _ProductSell.ProductDescription = txtListingDescription.Value;
        #region Add Image
        if (FULImg.HasFile)
        {
            string path = Server.MapPath(RTISettings.NewsPictureFolder);
            try
            {
                if (_ProductSell.Image != null && File.Exists(Path.Combine(path, _ProductSell.Image)))
                {
                    File.Delete(Path.Combine(path, _ProductSell.Image));
                }
                if (_ProductSell.ThumbnailImage != null && File.Exists(Path.Combine(path, _ProductSell.ThumbnailImage)))
                {
                    File.Delete(Path.Combine(path, _ProductSell.ThumbnailImage));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            _ProductSell.Image = Utilitys.UploadFileImage(FULImg.PostedFile, path, 100, 100, RTISettings.MaxFileSize, true);
            _ProductSell.ThumbnailImage = Utilitys.UploadFileImage(FULImg.PostedFile, path, 500, 500, RTISettings.MaxFileSize, true);
        }
        #endregion
        _ProductSell.CatId = long.Parse(ddlSubSubCat.SelectedValue);
        _ProductSell.KeyWord = txtproductkey.Value;
        if (this.Id != long.MinValue && this.Id != 0)
        {
            ProductSellService.UpdateProductSell(_ProductSell);
            Criteria cri = new Criteria();
            cri.add(AddMoreSellProductColumns.ProductId, 0, Condition.EQUAL, Condition.AND);
            AddMoreSellProductCollection _AddMoreSellProductCollection = AddMoreSellProductService.GetAddMoreSellProductListByParam(AddMoreSellProductColumns.AddMoreId, OrderDirection.ASC, cri.Criter);
            if (_AddMoreSellProductCollection.Count > 0)
            {

                for (int i = 0; i < _AddMoreSellProductCollection.Count; i++)
                {
                    AddMoreSellProduct _AddMoreSellProduct = AddMoreSellProductService.GetAddMoreSellProduct(_AddMoreSellProductCollection[i].AddMoreId);
                    _AddMoreSellProduct.ProductId = this.Id;
                    AddMoreSellProductService.UpdateAddMoreSellProduct(_AddMoreSellProduct);
                }
            }
            Response.Redirect(string.Format("MProductsell.aspx?id={0}&con1={1}&con2={2}", this.Id, "1","0"));
        }
        else
        {
            _ProductSell.Enable = true;
            _ProductSell.CreatedDate = DateTime.Now;
            ProductSellService.CreateProductSell(_ProductSell);
            long IdNew = _ProductSell.ProductId;
            Criteria cri = new Criteria();
            cri.add(AddMoreSellProductColumns.ProductId, 0, Condition.EQUAL, Condition.AND);
            AddMoreSellProductCollection _AddMoreSellProductCollection = AddMoreSellProductService.GetAddMoreSellProductListByParam(AddMoreSellProductColumns.AddMoreId, OrderDirection.ASC, cri.Criter);
            if (_AddMoreSellProductCollection.Count > 0)
            {

                for (int i = 0; i < _AddMoreSellProductCollection.Count; i++)
                {
                    AddMoreSellProduct _AddMoreSellProduct = AddMoreSellProductService.GetAddMoreSellProduct(_AddMoreSellProductCollection[i].AddMoreId);
                    _AddMoreSellProduct.ProductId = IdNew;
                    AddMoreSellProductService.UpdateAddMoreSellProduct(_AddMoreSellProduct);
                }
            }
            Response.Redirect(string.Format("MProductsell.aspx?id={0}&con1={1}&con2={2}", _ProductSell.ProductId, "1","0"));
        }
    }
    protected void lbtback1_OnClick(object sender, EventArgs e)
    {
        if (this.Id != long.MinValue && this.Id != 0)
        {
            Response.Redirect(string.Format("MProductsell.aspx?id={0}&con1={1}&con2={2}", this.Id, "0","0"));
        }
    }
    protected void lbtContinues2_OnClick(object sender, EventArgs e)
    {
        ADESSA.Entities.ProductSell _ProductSell = new ADESSA.Entities.ProductSell();
        if (this.Id != long.MinValue && this.Id != 0)
        {
            _ProductSell = ProductSellService.GetProductSell(this.Id);
        }
        _ProductSell.Title = txtName.Value;
        _ProductSell.ProductDescription = txtListingDescription.Value;
        #region Add Image
        if (FULImg.HasFile)
        {
            string path = Server.MapPath(RTISettings.NewsPictureFolder);
            try
            {
                if (_ProductSell.Image != null && File.Exists(Path.Combine(path, _ProductSell.Image)))
                {
                    File.Delete(Path.Combine(path, _ProductSell.Image));
                }
                if (_ProductSell.ThumbnailImage != null && File.Exists(Path.Combine(path, _ProductSell.ThumbnailImage)))
                {
                    File.Delete(Path.Combine(path, _ProductSell.ThumbnailImage));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            _ProductSell.Image = Utilitys.UploadFileImage(FULImg.PostedFile, path, 100, 100, RTISettings.MaxFileSize, true);
            _ProductSell.ThumbnailImage = Utilitys.UploadFileImage(FULImg.PostedFile, path, 500, 500, RTISettings.MaxFileSize, true);
        }
        #endregion
        _ProductSell.Description = txtDetailDescription.Value;
        ProductSellService.UpdateProductSell(_ProductSell);
        Response.Redirect(string.Format("MProductsell.aspx?id={0}&con1={1}&con2={2}", this.Id, "0", "2"));
    }
    protected void lbtback2_OnClick(object sender, EventArgs e)
    {
        Response.Redirect(string.Format("MProductsell.aspx?id={0}&con1={1}&con2={2}", this.Id, "1", "0"));
    }
    protected void ltbfinish_OnClick(object sender, EventArgs e)
    {
        ADESSA.Entities.ProductSell _ProductSell = new ADESSA.Entities.ProductSell();
        if (this.Id != long.MinValue && this.Id != 0)
        {
            _ProductSell = ProductSellService.GetProductSell(this.Id);
            _ProductSell.MinOrderQuantity = txtMinOderQuantity.Value;
            _ProductSell.MinQuantityTypeId = long.Parse(ddlUnittype1.SelectedValue);
            _ProductSell.MinQuantityOther = txtMinOtherQuantity.Value;

            _ProductSell.FOBPriceId = long.Parse(ddlCurency.SelectedValue);
            _ProductSell.PriceSmall = txtFOBPrice1.Value;
            _ProductSell.PriceLarge = txtFOBPrice2.Value;
            _ProductSell.PerTypeId = long.Parse(ddlUnittype2.SelectedValue);

            _ProductSell.Port = txtPort.Value;
            _ProductSell.PaymentTerms = txtPaymentTerms.Value;
            _ProductSell.Production = txtProductionCapacity.Value;
            _ProductSell.DeliveryTime = txtDeliveryTime.Value;
            _ProductSell.PackagingDetail = txtPackagingDetails.Value;
            _ProductSell.Order = 100;

            _ProductSell.Title = txtName.Value;
            _ProductSell.ProductDescription = txtListingDescription.Value;
            #region Add Image
            if (FULImg.HasFile)
            {
                string path = Server.MapPath(RTISettings.NewsPictureFolder);
                try
                {
                    if (_ProductSell.Image != null && File.Exists(Path.Combine(path, _ProductSell.Image)))
                    {
                        File.Delete(Path.Combine(path, _ProductSell.Image));
                    }
                    if (_ProductSell.ThumbnailImage != null && File.Exists(Path.Combine(path, _ProductSell.ThumbnailImage)))
                    {
                        File.Delete(Path.Combine(path, _ProductSell.ThumbnailImage));
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
                _ProductSell.Image = Utilitys.UploadFileImage(FULImg.PostedFile, path, 100, 100, RTISettings.MaxFileSize, true);
                _ProductSell.ThumbnailImage = Utilitys.UploadFileImage(FULImg.PostedFile, path, 500, 500, RTISettings.MaxFileSize, true);
            }
            #endregion
            ProductSellService.UpdateProductSell(_ProductSell);
        }
        Response.Redirect("Sellingleads.aspx");
        
    }
}
